package com.sky.controller.admin;

import com.sky.properties.AliOssProperties;
import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/admin/common")
@Api(tags = "我是通用类！alioss")
public class CommonController {

    @Autowired
    AliOssUtil aliOssUtil;

    @RequestMapping("/upload")
    @ApiOperation("我用来上传文件")
    public Result upload(MultipartFile file, NativeWebRequest nativeWebRequest) throws IOException {
        String name = file.getOriginalFilename();
        String houzhui = name.substring(name.lastIndexOf("."));
        String newName = UUID.randomUUID().toString()+houzhui;
        System.out.println("(😄)根据文件拼接后我要上船的文件newName叫"+newName);
        String pathToOss = aliOssUtil.upload(file.getBytes(),newName);
        return Result.success(pathToOss);
    }
}
